package main
import(

	"fmt"
)

/**
已知有一个升序数组，要求插入一个元素，最后打印该数组，顺序依然是升序
*/
func main(){
	arr := [...]int{1,2,4,5,6}
	arr1 := insert(&arr,3)
	fmt.Println("ar1r=",arr1)
}

func insert(arr *[5]int,insertVal int)  [6]int{
	var newArr [6]int
	var index int =0
	for i:=0;i<len(arr);i++{
		if (*arr)[i]>insertVal{
		
			newArr[i] = insertVal
			newArr[i+1] = (*arr)[i]
			index = i+1
			break
		}else{
			newArr[i] = (*arr)[i]
		}
	}

	for i := index;i<len(arr);i++{
		newArr[i+1] =(*arr)[i]
	}

	return newArr
}